/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.J2SE.Thread;

/**
 *
 * @author kylin
 */
public class TestThreadJoin2 extends Thread{
    public TestThreadJoin2(String name){
        super(name);
    }
    public void run(){
        for(int i=0;i<100;i++){
            System.out.println(getName()+" "+i);
        }
    }
    public static void main(String args[]) throws Exception{
        new TestThreadJoin2("新线程").start();
        for(int i=0;i<100;i++){
            if(i==20){
                TestThreadJoin2 thj=new TestThreadJoin2("被join的线程");
                thj.start();
                //main线程调用了thj线程的join()方法，main线程必须等待thj线程执行结束后才会向下执行
                thj.join();
            }
            System.out.println(Thread.currentThread().getName()+" "+i);
        }
    }
}
